/**
 * @CopyRight weitaming.com
 * @author wuyahui
 * @E-mail wuyahui@ispied.com
 * @version 1.0.0
 * @Date  2014年5月6日 上午11:12:52
 */
package com.tstudy.laoshibang.manager;

import java.util.ArrayList;
import java.util.List;

import com.tstudy.laoshibang.base.BaseApplication;
import com.tstudy.laoshibang.db.DBManagerImpl;
import com.tstudy.laoshibang.mode.Dictionary;
import com.tstudy.laoshibang.utils.CommonUtil;
import com.tstudy.laoshibang.utils.LogUtil;

import android.text.TextUtils;

public class DictionaryManager extends DBManagerImpl {
	private DictionaryManager() {
	}

	public static DictionaryManager instance = new DictionaryManager(Dictionary.class);

	private DictionaryManager(Class<Dictionary> clazz) {
		super(clazz);
	}

	public static DictionaryManager getInstance() {
		return instance;
	}

	/**
	 * 初始化缓存城市列表
	 */
	public void initDictionaryData() {
		int count = getCount();
		if (count > 0) {
			return;
		}
		long beginTime = System.currentTimeMillis();
		List<String> list = CommonUtil.readFileToList(
				BaseApplication.mContext, "dictionary");
		ArrayList<Dictionary> dictionarys = new ArrayList<Dictionary>();
		for (String str : list) {
			if (!TextUtils.isEmpty(str)) {
				String[] cityArray = str.split(",");
				if (cityArray.length == 3) {
					String type = cityArray[0];
					int key = Integer.parseInt(cityArray[1]);
					String name = cityArray[2];
					Dictionary dic = new Dictionary(key, name,type);
					dictionarys.add(dic);
				}
			}
		}
		insert(dictionarys);

		long executeTime = System.currentTimeMillis() - beginTime;
		LogUtil.d("--initDictionaryDatatime ==" + executeTime);
	}

}
